package cn.tannn.tcache.command.string;

import cn.tannn.tcache.core.Command;
import cn.tannn.tcache.core.Reply;
import cn.tannn.tcache.core.Tcache;

/**
 * get 命令 [获取value]
 * <p> get k1
 *
 * @author <a href="https://t.tannn.cn/">tnnn</a>
 * @version V1.0
 * @date 2024/6/19 下午9:08
 */
public class GetCommand implements Command {
    @Override
    public String name() {
        return "GET";
    }

    @Override
    public Reply<?> exec(Tcache cache, String[] args) {
        String key = getKey(args);
        String value = cache.get(key);
        if (value == null) {
            return Reply.error(" not exist key : " + key);
        }
        return Reply.bulkString(value);
    }
}
